package com.doge.controller.admin;



import com.doge.bean.base.BaseParam;
import com.doge.bean.base.BaseRespVo;
import com.doge.bean.bo.issue.IssueCreateBO;
import com.doge.bean.pojo.issue.Issue;
import com.doge.bean.vo.issue.IssueListVO;
import com.doge.bean.vo.issue.IssueNoDeletedVO;
import com.doge.service.admin.issue.IssueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName: IssueController
 * @Description: 通用问题管理
 * @author: PuJing
 * @create: 2021-11-30-16:03
 **/
@RestController
@RequestMapping("admin/issue")
public class IssueController {

    @Autowired
    IssueService issueService;

    /**
     * 查询指定条件的问题信息
     * http://182.92.235.201:8083/admin/issue/list?
     * page=1&limit=20&question=%E8%B4%AD%E4%B9%B0&sort=add_time&order=desc
     *
     * @param param
     * @param question 问题
     * @return
     */
    @RequestMapping("list")
    public BaseRespVo list(BaseParam param,String question){

          //question是null或"xxx"或""

          IssueListVO issueListVO = issueService.list(param,question);

          return BaseRespVo.ok(issueListVO);
    }

    /**
     * 创建问题
     * @param issueCreateBO 接收问题
     * @return
     */
    @RequestMapping("create")
    public BaseRespVo create(@RequestBody IssueCreateBO issueCreateBO){

        IssueNoDeletedVO issueNoDeletedVO = issueService.create(issueCreateBO);

        return BaseRespVo.ok(issueNoDeletedVO);
    }

    /**
     * 修改问题
     * @param issue
     * @return
     */
    @RequestMapping("update")
    public BaseRespVo update(@RequestBody Issue issue){

        Issue issueUpdate = issueService.update(issue);

        return BaseRespVo.ok(issueUpdate);
    }

    /**
     * 删除问题
     * @param issueNoDeletedVO
     * @return
     */
    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody IssueNoDeletedVO issueNoDeletedVO){

        int code = issueService.delete(issueNoDeletedVO);

        if (code == 200) {
            return BaseRespVo.ok();
        } else {
            return BaseRespVo.error(621, "删除问题失败");
        }
    }

}
